package com.consente.demo;

import com.alibaba.druid.pool.DruidDataSource;
import com.consente.demo.netty.service.NettyServerStarterTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
public class NettyApplicationListener implements ApplicationRunner {
    @Autowired
    private NettyServerStarterTemplate nettyServerStarterTemplate;
//    @Override
//    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
//        System.out.println("netty 启动 =========================================================!");
//        nettyStarter.start();
//    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("Socket Start");
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                nettyServerStarterTemplate.start();
            }
        });
    }



}
